package auctionhaus



import grails.test.mixin.*
import org.junit.*
import org.grails.datastore.mapping.model.types.Simple

/**
 * See the API for {@link grails.test.mixin.domain.DomainClassUnitTestMixin} for usage instructions
 */
@TestFor(Customer)
class CustomerTests {

    public  void setUp() {
        mockForConstraintsTests(Customer)
    }

    void testBlankValidation() {
        def blankCustomer = new Customer()
        assert !blankCustomer.validate()
    }
    
    void testEmailConstraints() {
        def existingCustomer = new Customer(
                email: "johndoe@acme.com",
                password: "1234567"
        )
        mockForConstraintsTests(Customer, [existingCustomer])

        //test malformed email
        def badEmailCustomer = new Customer(
                email: "johndoeatacme.com",
                password: "123457"
        )
        assert !badEmailCustomer.validate()
        
        //test non-unique email
        def duplicateCustomer = new Customer(
                email: "johndoe@acme.com",
                password: "1122334"
        )
        assert !duplicateCustomer.validate()
        
        //test valid email
        def goodEmailCustomer = new Customer(
                email: "jane.doe@acme.com",
                password: "1234567"
        )
        assert goodEmailCustomer.validate()
    }

    void testPasswordConstraints() {
        
        def shortPassword = new Customer(
                email: "johndoe@acme.com",
                password: "123"
        )
        assert !shortPassword.validate()
        
        def longPassword = new Customer(
                email: "janedoe@acme.com",
                password: "123456789"
        )
        assert !longPassword.validate()
        
        def lowBoundary = new Customer(
                email: "lowBound@acme.com",
                password: "123456"
        )
        assert lowBoundary.validate()
        
        def upBoundary = new Customer(
                email: "upBound@acme.com",
                password: "12345678"
        )
        assert  upBoundary.validate()

        def typical = new Customer(
                email: "typical@acme.com",
                password: "asdEF1!"
        )
        assert typical.validate()
    }

    void testDateConstraints() {
        def customer = new Customer(
                email: "johndoe@acme.com",
                password: "1234567"
        )
        assert customer.validate()
    }

    public void tearDown() {

    }
}
